import utils.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/3 12:40
 * @description:
 */
public class Solution144 {
    List<Integer> res;
    public List<Integer> preorderTraversal(TreeNode root) {
        res = new ArrayList<>();
        traverse(root);
        return res;
    }
    public void traverse(TreeNode root) {
        if(root == null){
            return;
        }
        res.add(root.val);
        traverse(root.left);
        traverse(root.right);
    }
}
